﻿/*
 * Copyright 2021 Qter(qsaker@qq.com). All rights reserved.
 *
 * The file is encoded using "utf8 with bom", it is a part
 * of QtSwissArmyKnife project.
 *
 * QtSwissArmyKnife is licensed according to the terms in
 * the file LICENCE in the root of the source code directory.
 */
#ifndef SAKBLUETOOTHSERVERDEVICE_HH
#define SAKBLUETOOTHSERVERDEVICE_HH

#include <QThread>
#include <QTcpServer>
#include <QTcpSocket>

#include "SAKDebugPageDevice.hh"

class SAKBluetoothServerDebugPage;
class SAKBluetoothServerDeviceController;
class SAKBluetoothServerDevice:public SAKDebugPageDevice
{
    Q_OBJECT
public:
    SAKBluetoothServerDevice(SAKBluetoothServerDebugPage *mDebugPage, QObject *parent = Q_NULLPTR);
private:
    bool initializing(QString &errorString) final;
    bool open(QString &errorString) final;
    QByteArray read() final;
    QByteArray write(QByteArray bytes) final;
    bool checkSomething(QString &errorString) final;
    void close() final;
    void free() final;
signals:
    void addClient(QString host, quint16 port, QTcpSocket *socket);
    void removeClient(QTcpSocket *socket);
private:
    SAKBluetoothServerDebugPage *mDebugPage;
    QTcpServer *mTcpServer;
    SAKBluetoothServerDeviceController *mDeviceController;
    QList<QTcpSocket*> mClientList;
};

#endif
